import { h, resolveComponent, defineComponent, VNode } from 'vue'
import type { ElTableColumn } from 'element-plus' // 正确导入方式

export default defineComponent({
  name: 'CustomTableColumn',
  render(): VNode {
    return h(
      resolveComponent('el-table-column') as typeof ElTableColumn,
      {
        index: this.index,
        ...this.$attrs
      },
      this.$slots
    )
  },
  methods: {
    index(index: number): number {
      if (this.$attrs.type === 'index') {
        // 更安全的父组件访问方式
        const pagination = (this.$parent?.$parent as any)?.pagination || {
          currentPage: 1,
          pageSize: 10
        }
        return (pagination.currentPage - 1) * pagination.pageSize + index + 1
      }
      return index
    }
  }
})